package com.zeen.zl.controller;

import com.zeen.zl.domain.User;
import com.zeen.zl.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * user controller 入口
 * @author Z.L.G
 */
@Controller()
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @RequestMapping("/hello")
    public String hello(Model model) {
        model.addAttribute("msg","welcome you....");
        return "hello2";
    }

    @RequestMapping("/get")
    @ResponseBody
    public String get(@RequestParam("id") Long id) {
        return userService.get(id).getUserName();
    }

    @RequestMapping("/add")
    @ResponseBody
    public String add(User user) {
        userService.save(user);
        return  "Add OK";
    }

}
